const classlist = []
import Mock from 'mockjs'

for(var i = 0;i < 100;i++){
    classlist.push(
        {
            id: Mock.mock('@zip()'),
            classname:Mock.mock('@ctitle(5)') +'课程',
            price:Mock.mock('@integer(100, 600)') , 
            sall:Mock.mock('@integer(100, 1000)') ,
            autor:Mock.mock('@first'),
            time:Mock.mock('@date()'),
            Image:'../../../assets/iconfont/04课程管理/kecheng-picture0' + Mock.mock('@integer(1, 8)') + '.png',
            Image1:'item0' + Mock.mock('@integer(1, 8)'),
        }
    )
    
    }

    //引入提取url的工具
    import{ param2Obj} from '../utls/classutils'

export default{
// 查询接口
  getclassData:(config)=>{
    // console.log(config);   //post请求参数在body,get请求参数在url上,
    // console.log(param2Obj(config.url));
// 查询逻辑

    var {keyword,page,pagesize} = param2Obj(config.url)
    var newarr = classlist.filter(item=>item.classname.indexOf(keyword) !=-1)
//分页公式
//(page-1)*pagesize<= index < page*pagesize
var pageresult = newarr.filter((item,index)=>{
  return (page-1)*pagesize<= index && index < page*pagesize
})


return{
code:200,
msg:'请求成功',
data:pageresult,
totol:classlist.length

}

  },


  // 删除接口
  deleteData(config){
  // console.log(config);
  var id = JSON.parse(config.body).id
  // console.log(id);
  classlist.forEach((item,index)=>{
if(item.id == id){
  classlist.splice(index,1)
}
  })

return{
code:200,
msg:'删除成功',
data:null
}
  },

// 编辑接口
updataHander:config=>{
 var{id,classname,peple,price,sall,time} = JSON.parse(config.body)
 classlist.forEach(item=>{
if(item.id == id){
item.classname = classname
item.price = price
item.sall = sall
item.time = time
item.autor = peple

}

 })

console.log(JSON.parse(config.body));
return{
  code:200,
  msg:'修改成功',
  data:null
}

}


    }
   